package com.common.preimgloader;

import android.annotation.SuppressLint;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;

import com.previewlibrary.enitity.IThumbViewInfo;

@SuppressLint("ParcelCreator")
public class ImageBean implements IThumbViewInfo {
    private String url;  //图片地址
    private Rect mBounds; // 记录坐标
    private String user;//
    private String videoUrl;//视频链接 //不为空是视频

    public ImageBean(String url, Rect mBounds) {
        this.url = url;
        this.mBounds = mBounds;
    }

    @Override
    public String getUrl() {
        return url;
    }

    @Override
    public Rect getBounds() {
        return mBounds;
    }

    @Nullable
    @Override
    public String getVideoUrl() {
        return null;
    }

    @Override
    public int describeContents() {
        return 0;
    }
    /**
     * 必须实现Parcelable.Creator接口，否则在获取该类数据的时候会报错
     *
     * android.os.BadParcelableException:Parcelable protocol requires a
     * Parcelable.Creator object called CREATOR on class
     *
     * Parcelable.Creator接口实现了从Parcel容器读取本对象（Teacher）数据，并返回该对象给逻辑层使用
     *
     * Parcelable.Creator接口对象名必须为CREATOR,否则同样会报上述同样的错误；
     *
     * 在读取Parcel容器中的数据事，必须按成员变量声明的顺序来读取数据，不然会出现获取数据错误；
     *
     * 反序列化对象
     */
    public static final Parcelable.Creator<ImageBean> CREATOR = new Creator<ImageBean>() {

        @Override
        public ImageBean createFromParcel(Parcel source) {
            ImageBean teacher = new ImageBean(source.readString(),new Rect());
            return teacher;
        }

        @Override
        public ImageBean[] newArray(int size) {
            // TODO Auto-generated method stub
            return new ImageBean[size];
        }
    };
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(url);
    }
}
